<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="<%=WEBPATH%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=WEBPATH%>/dwr/util.js"></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/MenuAction.js'></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/MenuBean.js'></script> 
<title><html:text name="sys.name" /></title>
</head>
<body>
<table width="100%">
	<tr>
		<td height="500" width="15%" valign="top">
			<script type="text/javascript" charset="UTF-8">
						webFXTreeConfig.rootIcon		= "<%=WEBPATH%>/images/xloadtree/page_white_magnify.gif";
						webFXTreeConfig.openRootIcon	= "<%=WEBPATH%>/images/xloadtree/page_white_magnify.gif";
						webFXTreeConfig.folderIcon		= "<%=WEBPATH%>/images/xloadtree/folder.png";
						webFXTreeConfig.openFolderIcon	= "<%=WEBPATH%>/images/xloadtree/openfolder.png";
						webFXTreeConfig.fileIcon		= "<%=WEBPATH%>/images/xloadtree/page_white_gear.gif";
						webFXTreeConfig.lMinusIcon		= "<%=WEBPATH%>/images/xloadtree/Lminus.png";
						webFXTreeConfig.lPlusIcon		= "<%=WEBPATH%>/images/xloadtree/Lplus.png";
						webFXTreeConfig.tMinusIcon		= "<%=WEBPATH%>/images/xloadtree/Tminus.png";
						webFXTreeConfig.tPlusIcon		= "<%=WEBPATH%>/images/xloadtree/Tplus.png";
						webFXTreeConfig.iIcon			= "<%=WEBPATH%>/images/xloadtree/I.png";
						webFXTreeConfig.lIcon			= "<%=WEBPATH%>/images/xloadtree/L.png";
						webFXTreeConfig.tIcon			= "<%=WEBPATH%>/images/xloadtree/T.png";
						webFXTreeConfig.blankIcon		= "<%=WEBPATH%>/images/xloadtree/blank.png";
						var treeDict = new WebFXTree("菜单",""); 
						<html:iterator value="menuChildBeans" id="menuChildBeans">
							<html:if test="child==0" >
								treeDict.add(new WebFXTreeItem("<html:property value="name"/>","javascript:showMenu('<html:property value="id"/>')","","<%=WEBPATH%>/images/xloadtree/folder.png"));
							</html:if>
							<html:else>
								treeDict.add(new WebFXLoadTreeItem("<html:property value="name"/>", "<%=WEBPATH%>/system/menu/child.crm?parentId=<html:property value="id"/>","javascript:showMenu('<html:property value="id"/>')"));
							</html:else>
						</html:iterator>
						document.write(treeDict);
						function showMenu(id){
							MenuAction.dwrView(id,fillMenu);
						}
						function fillMenu(data){
							jQuery('#id').val(data.id);
							jQuery('#name').val(data.name); 
							jQuery('#parentId').val(data.parentId);
							jQuery('#descn').val(data.descn);
							jQuery('#image').val(data.image);
							jQuery('#forward').val(data.forward);
							jQuery('#target').val(data.target);
							jQuery('#orderBy').val(data.orderBy);
							jQuery('#menuNewTable').hide();
							jQuery('#menuDeleteButton').hide();
							jQuery('#menuDeleteButton').show();
							jQuery('#menuDetailTable').show();
						}
						function menuNew(){
							jQuery('#id').val("");
							jQuery('#name').val("");
							jQuery('#parentId').val("0");
							jQuery('#descn').val("");
							jQuery('#image').val("");
							jQuery('#forward').val("");
							jQuery('#target').val("");
							jQuery('#orderBy').val("");
							jQuery('#menuNewTable').hide();
							jQuery('#menuUpdateNewButton').hide();							
							jQuery('#menuDeleteButton').hide();
							jQuery('#menuDetailTable').show();
						}
						function menuDelete(){
							if(confirm("确定删除?")){
								var id=jQuery('#id').attr("value");
								MenuAction.dwrDelete(id,callBackFunction);
							}
						}
						function menuSave(newFlag){  
							if(newFlag){ 
								//var parent={id: jQuery('#id').attr("value")};
								var temp=jQuery('#id').attr("value");
								if(temp==""||temp==null){
									temp="0";
								}
								var MenuBean={
									id: "",
									name: jQuery('#name').attr("value"),
									descn: jQuery('#descn').attr("value"),
									image: jQuery('#image').attr("value"),
									forward: jQuery('#forward').attr("value"),
									target: jQuery('#target').attr("value"),
									orderBy: jQuery('#orderBy').attr("value"),
									parentId: temp
								};
								MenuAction.dwrSave(MenuBean,callBackFunction);
							}else{ 
								var temp=jQuery('#parentId').attr("value");
								if(temp==""||temp==null){
									temp="0";
								}
								//var parent={id: temp};
								var MenuBean={
									id: jQuery('#id').attr("value"),
									name: jQuery('#name').attr("value"),
									descn: jQuery('#descn').attr("value"),
									image: jQuery('#image').attr("value"),
									forward: jQuery('#forward').attr("value"),
									target: jQuery('#target').attr("value"),
									orderBy: jQuery('#orderBy').attr("value"),
									parentId: temp
								};
								MenuAction.dwrSave(MenuBean,callBackFunction);
							}	
						}
						function callBackFunction(data){
							alert(data);
							window.location="<%=WEBPATH%>/system/menu/index.crm";
						}
				</script>
		</td>
		<td width="85%" valign="top">
			<table id="menuNewTable" width="100%">
				<tr>
					<td align="right"><input type="button" name="menuNewButton" id="menuNewButton"  value=" <html:text name="button.new"/> " style="width:90px;" onclick="javascript:menuNew();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
				</tr>
			</table>
			<table id="menuDetailTable" width="100%" style="display:none;">
				<tr><td colspan="2" align="right"><input type="button" name="menuUpdateNewButton" id="menuUpdateNewButton"  value=" <html:text name="button.new"/> " style="width:90px;" onclick="javascript:menuSave(true);">&nbsp;&nbsp;
				<input type="button" name="menuDeleteButton" id="menuDeleteButton"  value=" <html:text name="button.delete"/> " style="width:90px;" onclick="javascript:menuDelete();">&nbsp;&nbsp;
				<input type="button" name="menuSaveButton" id="menuSaveButton"  value=" <html:text name="button.save"/> " style="width:90px;" onclick="javascript:menuSave(false);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				<tr>
					<td width="20%" style="text-align:right;"><html:text name="menu.name"></html:text></td>
					<td width="80%"><input type="hidden" name="id" id="id"><input type="text" name="name" id="name"  style="width:95%"></input><span class="star">*</span></td>
				</tr>
				<tr>
					<td style="text-align:right;"><html:text name="menu.descn"></html:text></td>
					<td><input type="hidden" name="parentId" id="parentId"><input type="text" name="descn" id="descn"  style="width:95%"></input></td>
				</tr>
				<tr>
					<td style="text-align:right;"><html:text name="menu.image"></html:text></td>
					<td><input type="text" name="image" id="image"  style="width:95%"></input></td>
				</tr>
				<tr>
					<td style="text-align:right;"><html:text name="menu.forward"></html:text></td>
					<td><input type="text" name="forward" id="forward"  style="width:95%"></input><span class="star">*</span></td>
				</tr>
				<tr>
					<td style="text-align:right;"><html:text name="menu.target"></html:text></td>
					<td><input type="text" name="target" id="target"  style="width:95%"></input></td>
				</tr>
				<tr>
					<td style="text-align:right;"><html:text name="menu.orderBy"></html:text></td>
					<td><input type="text" name="orderBy" id="orderBy"  style="width:95%"></input></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</body>
</html>
